/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-07-30     andy       the first version
 */
 #include <rtthread.h>
#include "dfs_fs.h"

#include "sdio_tfcard_fatfs_port.h"     //声明sd卡在文件系统的挂载点
#define SD_DEV_NAME   "sd0"             //sd卡设备名称

#define DBG_TAG "mount_fs"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>





int sdio_tfcard_mnt_init(void)
{
    rt_thread_delay(RT_TICK_PER_SECOND);

    if(rt_device_find(SD_DEV_NAME) != RT_NULL)
    {
        if (dfs_mount(SD_DEV_NAME, SDIO_SDCARD_PATH, "elm", 0, 0) == RT_EOK)
        {
           LOG_I("sd card mount to %s", SDIO_SDCARD_PATH);
           return RT_EOK;
        }
        else
        {
            if(dfs_mkfs("elm", SD_DEV_NAME) == 0)
            {
                if (dfs_mount(SD_DEV_NAME, SDIO_SDCARD_PATH, "elm", 0, 0) == RT_EOK)
                {
                    LOG_I("sd card mount to %s", SDIO_SDCARD_PATH);
                    return RT_EOK;
                }
                else
                {
                    LOG_W("sd card mount failed");
                }
            }

        }
    }

    return RT_ERROR;
}
INIT_ENV_EXPORT(sdio_tfcard_mnt_init);
